package colab.gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JList;
import javax.swing.JLabel;

import colab.dominio.Predio;
import colab.persistencia.SalasDAO;

import com.jgoodies.forms.factories.DefaultComponentFactory;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.SwingConstants;

import java.awt.Color;

import javax.swing.ImageIcon;

public class TelaSalasPredio extends JFrame {

	private JPanel contentPane;
	private JComboBox<String> cb;
	
	private SalasDAO sala_dao=new SalasDAO();
	private Predio predio=new Predio();
	/**
	 * Launch the application.
	 */
	

	/**
	 * Create the frame.
	 */
	public TelaSalasPredio(Predio _predio) {
		this.predio= _predio;
		
		try {
			String[] salas = new String[sala_dao.listarSalas(predio).size()];
			for (int i = 0; i <sala_dao.listarSalas(predio).size() ; i++) {
				System.out.println("entrou");
				salas[i] ="Lab: " + Integer.toString(sala_dao.listarSalas(predio).get(i).getId_sala());
			}
			cb = new JComboBox<String>(salas);
			cb.setBounds(20,50, 80, 40);
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
		
		
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 564, 453);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(255, 255, 255));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		contentPane.add(cb);
		
		
		JLabel lblSalas = DefaultComponentFactory.getInstance().createLabel("Salas");
		lblSalas.setHorizontalAlignment(SwingConstants.RIGHT);
		lblSalas.setFont(new Font("Tahoma", Font.PLAIN, 20));
		lblSalas.setBounds(136, 11, 117, 21);
		contentPane.add(lblSalas);
		
		JLabel lblPredio = DefaultComponentFactory.getInstance().createLabel(predio.getNome());
		lblPredio.setHorizontalAlignment(SwingConstants.LEFT);
		lblPredio.setFont(new Font("Tahoma", Font.PLAIN, 20));
		lblPredio.setBounds(263, 11, 117, 21);
		contentPane.add(lblPredio);
		setVisible(true);
		setResizable(false);
		
		JButton button =new JButton("Ir");
		button.setBounds(208,114,82,33);
		contentPane.add(button);
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon("C:\\workspace\\CO-LAB\\src\\colab\\gui\\imagens\\COLAB-001.PNG"));
		label.setBounds(111, 79, 558, 425);
		contentPane.add(label);
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try{
					TelaSala tela=new TelaSala(predio.getNome(), 30, 30, 400, 400, sala_dao.listarSalas(predio).get(cb.getSelectedIndex()));
					tela.setVisible(true);
				}
				catch (Exception e){
					e.printStackTrace();
				}
			}
		});
		
		JButton btnVoltar = new JButton("Voltar");
		btnVoltar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				TelaPredio tela=new TelaPredio();
				tela.setVisible(true);
				dispose();
			}
		});
		btnVoltar.setBounds(449, 83, 89, 23);
		contentPane.add(btnVoltar);
	}
}